<!--
 * @Descripttion: 统计
 * @LastEditors: xzh
 * @LastEditTime: 2023-11-08 20:28:24
-->
<template>
  <div class="afterSale-statistic">
    <el-card
      class="el-card-bottom-top"
      v-loading="loading"
      v-for="statistic in AfterSaleUtils.statisticMap.filter((x:object_Inf) =>
        !!type ? x.type == type : true
      )"
      :key="statistic.value"
      @click="!loading && hanldeStatisticDetails(statistic.value)"
    >
      <div class="statistic-label">
        <h2>{{ $t(statistic.label) }}</h2>
      </div>
      <div class="statistic-content">
        <div class="statistic-icon">
          <SvgIcon :size="3" :name="statistic.icon" :color="statistic.color" />
        </div>
        <div class="statistic-value">
          <p>{{ $t(statistic.content) }}</p>
          <div>
            <template v-if="!!dataMap[statistic.value]">
              <CountTo :endVal="dataMap[statistic.value]?.split('/')[0] || 0" />
              <span>/</span>
              <CountTo :endVal="dataMap[statistic.value]?.split('/')[1] || 0" />
            </template>
            <span v-else>0</span>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import { CountTo } from "vue3-count-to";
import { object_Inf } from "@/utils/typings/index.type";
import SvgIcon from "@/assets/icons/index.vue";
import AfterSaleUtils from "../afterSale-utils";
import router from "@/router";
const props = defineProps({
  //统计数据源
  dataMap: {
    type: Object,
    requited: true,
    default: {},
  },
  loading: {
    type: Boolean,
    requited: true,
    default: false,
  },
  type: {
    type: String,
    requited: true,
    default: "",
  },
});
/**
 * @Author: xzh
 * @Descripttion: 统计详情
 * @Param:
 * @param {*} statisticType
 */
let hanldeStatisticDetails = (statisticType: string) => {
  let { type } = props;
  router.push({
    name: `afterSaleStatisticDetails${!!type ? `_${type}` : ""}`,
    query: { statisticType },
  });
};
</script>
<style lang="scss" scoped>
.afterSale-statistic {
  display: flex;
  justify-content: flex-start;
  .el-card {
    display: flex;
    flex: 12rem;
    &:hover {
      box-shadow: 0px 0px 0.75rem rgba(0, 0, 0, 0.24) !important;
      cursor: pointer;
    }
    :deep(.el-card__body) {
      height: max-content !important;
      flex-direction: column;
      > div {
        display: flex;
        padding: 0.5rem;
      }
      .statistic-label {
        align-items: center;
        h2 {
          color: #1d253b;
          font-size: 1.5rem;
          font-weight: 100;
        }
      }
      .statistic-content {
        justify-content: space-between;
        .statistic-value {
          display: flex;
          flex-direction: column;
          p {
            color: grey;
            font-weight: 400;
            font-size: 0.75rem;
          }
          > div {
            color: #1d253b;
            font-weight: 500;
            font-size: 1.437499875rem;
          }
        }
      }
    }
  }
}
</style>
